<!DOCTYPE html>
<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">


<title>新闻动态编辑</title>
<meta name="keywords" content="">
<meta name="description" content="">
<link href="${ctxPath}/static/admin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
<script src="${ctxPath}/static/admin/js/plugins/sweetalert/sweetalert.min.js"></script>

<link rel="stylesheet" type="text/css" href="${ctxPath}/static/admin/js/plugins/wangEditor/dist/css/wangEditor.min.css">

<link rel="shortcut icon" href="${ctxPath}/views/admin/favicon.ico">
<link href="${ctxPath}/static/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="${ctxPath}/static/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="${ctxPath}/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="${ctxPath}/static/admin/css/animate.css" rel="stylesheet">
<link href="${ctxPath}/static/admin/css/style.css?v=4.1.0" rel="stylesheet">
	

</head>

<body class="gray-bg">

	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>新闻动态信息</h5>
						<div class="ibox-tools">
							<a class="close-link" href="${ctxPath}/news/index">
								<button type="button" class="btn btn-default btn-sm"
									style="position: absolute; margin-bottom: 0px; bottom: 0px; right: 0px;">返回上一页</button>
							</a>
						</div>
					</div>
					<div class="ibox-content">
						<form action="${ctxPath}/news/${url!}" method="post" name="form" id="form" class="form-horizontal">
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">新闻标题</label>
								<div class="col-sm-10">
									<div class="row">
										<div class="col-md-10">
											<input type="text" maxlength="24" placeholder="新闻标题" class="form-control"
												id="title" name="title"  value="${data.title!}">
												<input type="hidden" id="id" name="id"  value="${data.id!}">
										</div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<label class="col-sm-2 control-label">新闻内容</label>
								<div class="col-sm-10">
									<div class="row">
										<div class="col-md-10">
											<textarea id="content" name="content" style="height:400px;">
												${data.content!}
											</textarea>
										</div>
									</div>
								</div>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<button type="button" class="btn btn-primary" onclick="save();">保存内容</button>
									<a href="${ctxPath}/news/index" class="btn btn-white">取消</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>



	<!-- 全局js -->
	<script src="${ctxPath}/static/admin/js/jquery.min.js?v=2.1.4"></script>
	<script src="${ctxPath}/static/admin/js/bootstrap.min.js?v=3.3.6"></script>

	<!-- 自定义js -->
	<script src="${ctxPath}/static/admin/js/content.js?v=1.0.0"></script>
	
	<script type="text/javascript" src="${ctxPath}/static/admin/js/plugins/wangEditor/dist/js/lib/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="${ctxPath}/static/admin/js/plugins/wangEditor/dist/js/wangEditor.min.js"></script>

	<!-- iCheck -->
	<script src="${ctxPath}/static/admin/js/plugins/iCheck/icheck.min.js"></script>
	<script>
        $(document).ready(function () {
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });


        var editor = new wangEditor('content');
        editor.config.uploadImgUrl = '${ctxPath}/news/saveImg';
        editor.config.uploadImgFileName = 'myFileName'
        editor.config.menus = $.map(wangEditor.config.menus, function(item, key) {
            if (item === 'table') {
                return null;
            }
            if (item === 'video') {
                return null;
            }
            if (item === 'location') {
                return null;
            }
            if (item === 'insertcode') {
                return null;
            }
            if (item === 'fullscreen') {
                return null;
            }
            return item;
        });
        
     	// 自定义load事件
        editor.config.uploadImgFns.onload = function (resultText, xhr) {
            // resultText 服务器端返回的text
            // xhr 是 xmlHttpRequest 对象，IE8、9中不支持

            // 上传图片时，已经将图片的名字存在 editor.uploadImgOriginalName
            var originalName = editor.uploadImgOriginalName || '';  

            // 如果 resultText 是图片的url地址，可以这样插入图片：
            editor.command(null, 'insertHtml', '<img src="${ctxPath}/down/downNewsImg?imgUrl=' + resultText + '" alt="' + originalName + '" style="max-width:60em;"/>');
            // 如果不想要 img 的 max-width 样式，也可以这样插入：
            // editor.command(null, 'InsertImage', resultText);
        };
        editor.create();
    </script>
	<script type="text/javascript">
		function num_check(a){
	        var m =a ;
			var partten =/^\+?(0|[1-9][0-9]*)$/;
			if (m != '') {
				if (!partten.test(m)) {
					swal({
						  title: "提示",
						  text: "请输入整数",
						  timer: 1000,
						  showConfirmButton: false
						});
					return false;
				}
			}
		}
		
		
		//提交
        function save(){
        	if(editor.$txt.html() == null || editor.$txt.html() == "" || $("#title").val() == "" || $("#title").val() == null){
        		swal({
           		  title: "提示",
           		  text: "新闻标题或内容不可为空",
           		  timer: 1500,
           		  showConfirmButton: false
           		});
        		return false;
        	}
        	editor.$txt.html();
			$("#content").val(encodeURIComponent(encodeURIComponent(editor.$txt.html())));
			$("#content").val(decodeURIComponent(decodeURIComponent(editor.$txt.html())));
        	$.ajax({
                cache: true,
                type: "POST",
                url:'${ctxPath}/news/save',
                data:$('#form').serialize(),// 你的formid
                async: false,
                error: function(data) {
                	if(data.code == 1){
                		swal({
                   		  title: "提示",
                   		  text: "保存失败",
                   		  timer: 1500,
                   		  showConfirmButton: false
                   		});
                	}
                },success: function(data) {
                	if(data.code == 0){
                		swal({
                  		  title: "提示",
                  		  text: "保存成功,自动跳转页面中,请稍等...",
                  		  timer: 2000,
                  		  showConfirmButton: false
	                  	});
	                  	setTimeout(function(){
	                  		location.href="${ctxPath}/news/index";
	                  	},2000);
                	}
                }
            });
        }
	</script>



</body>

</html>
